// Eric McDonald1
// Tic Tac Tioe with hopefully working AI

#include <iostream>
using namespace std;

// Start of main program
int main()
{
	// Local Variable Decleration
	bool valid;
	BoardGrid ticTacToeBoard;
	secPlayer Player2;
	int pTurn = 1;

	
	// Loop that checks user input for valid option and continues game till someone wins.
	do
	{

		if (pTurn = 2)
		{
			Player2.pMove2(pTurn);
		}
		
		cout << "Your move, Meatbag" << endl;

		do 
		{
			char pMove;
			cin >> pMove;
			valid = true;

			

		
			if (pMove == '1' && boardPosition1 == '1')
			{
				boardPosition1 = 'X';
			} 
			else if (pMove == '2' && boardPosition2 == '2')
			{
				boardPosition2 = 'X';
			} 
			else if (pMove == '3' && boardPosition3 == '3')
			{
				boardPosition3 = 'X';
			} 
			else if (pMove == '4' && boardPosition4 == '4')
			{
				boardPosition4 = 'X';
			}
			else if (pMove == '5' && boardPosition5 == '5') 
			{
				boardPosition5 = 'X';
			} 
			else if (pMove == '6' && boardPosition6 == '6') 
			{
				boardPosition6 = 'X';
			} 
			else if (pMove == '7' && boardPosition7 == '7') 
			{
				boardPosition7 = 'X';
			} 
			else if (pMove == '8' && boardPosition8 == '8') 
			{
				boardPosition8 = 'X';
			}
			else if (pMove == '9' && boardPosition9 == '9') 
			{
				boardPosition9 = 'X';
			} 
			else 
			{
				std::cout << "Invalid Move. Try again." << std::endl;
				valid = false;
			}
		}while (!valid);

			
		
		// Game End and Win variables
		GameOver = false;
		GameWin = true;

		// Game End and Win checks
		if (boardPosition1 != '1')
		{
			if (boardPosition2 == boardPosition1 && boardPosition3 == boardPosition1)
			{
				GameOver = true;
			}
			if (boardPosition4 == boardPosition1 && boardPosition7 == boardPosition1)
			{
				GameOver = true;
			}

		}

		if (boardPosition5 != '5')
		{
			if (boardPosition1 == boardPosition5 && boardPosition9 == boardPosition5)
			{
				GameOver = true;
			}
			if (boardPosition2 == boardPosition5 && boardPosition8 == boardPosition5)
			{
				GameOver = true;
			}
			if (boardPosition4 == boardPosition5 && boardPosition6 == boardPosition5)
			{
				GameOver = true;
			}
			if (boardPosition3 == boardPosition5 && boardPosition7 == boardPosition5)
			{
				GameOver = true;
			}
		}

		if (boardPosition9 != '9')
		{
			if (boardPosition3 == boardPosition9 && boardPosition6 == boardPosition9)
			{
				GameOver = true;
			}
			if (boardPosition7 == boardPosition9 && boardPosition8 == boardPosition9)
			{
				GameOver = true;
			}
		}

		if (boardPosition1 != '1' && boardPosition2 != '2' && boardPosition3 != '3' &&
			boardPosition4 != '4' && boardPosition5 != '5' && boardPosition6 != '6' &&
			boardPosition7 != '7' && boardPosition8 != '8' && boardPosition9 != '9')
		{
			GameOver = true;
			GameWin = false;
		}


		if (GameOver)
		{
			if (GameWin)
			{
				cout << "You win this round, Meatbag...." << endl;
			}

			TicTacToeBoard.drawBoard();

			cout << "It seems we've filled the board. How humiliating." << endl;
			
			if (pTurn == 1)
			{
				pTurn = 2;

			}
			else 
			{
				pTurn = 1;
			}
		}
		

	} while(!GameOver);

return (0);
}



